package com.codejoys.ssm.dao;

import com.codejoys.ssm.domain.Thesis;
import com.codejoys.ssm.domain.ThesisDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ThesisDao {
    /**
     * 给某个课题加上排他锁
     *
     * @param tid --课题id
     */
    @Select("select * from thesis where id=#{tid} for update")
   Integer lockThesis(Integer tid);

    /**
     * 给某个学生id加锁
     * @param sid
     * @return
     */
    //todo 检查
    @Select("select id from user where id=#{id} for update")
    Integer lockStudent(Long sid);

    /**
     *
     * @param teacherId
     * @param year
     * @return
     */
    List<ThesisDto> findThesesOfTeacher(@Param("tid") Long teacherId, @Param("year") Short year);

    /**
     * 查询某个学生已经选定的课题
     * @param studentId  学生id
     * @return
     */
    @Select("SELECT * FROM student_thesis st "+
            "INNER JOIN thesis t ON st.tid=t.id"+
            "WHERE st.uid=#{id} AND t.`status`='3'")
    Thesis findSelectedThesis(Long studentId);



}
